package com.nuoniu.sibanyun.common.result;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.common.lang.StringUtils;

/**
 * HTTP结果封装
 *
 * @author Wang
 * @date June 12, 2019
 */
public class HttpResult<T> {

	private int code = 200;
	private String message;
	private T data;

	public static HttpResult error() {

		return error(ResultStatusCode.SYSTEM_ERR.getCode(), "未知异常，请联系管理员");
	}

	public static HttpResult error(String  message) {
		return error(ResultStatusCode.SYSTEM_ERR.getCode(),  message);
	}

	public static HttpResult error(ResultStatusCode resultStatusCode){
		return error(resultStatusCode.getCode(),  resultStatusCode.getMsg());
	}
	public static HttpResult error(ResultStatusCode resultStatusCode,String  message){
		if(StringUtils.isBlank(message)){
			message = resultStatusCode.getMsg();
		}
		return error(resultStatusCode.getCode(), message);
	}

	public static HttpResult error(int code, String  message) {
		HttpResult r = new HttpResult();
		r.setCode(code);
		r.setMessage( message);
		r.setData(false);
		return r;
	}

	public static HttpResult ok(String  message) {
		HttpResult r = new HttpResult();
		r.setMessage( message);
		return r;
	}
	public static HttpResult ok(String  message,Object data) {
		HttpResult r = new HttpResult();
		r.setMessage( message);
		r.setData(data);
		return r;
	}


	public static HttpResult ok(Object data) {
		HttpResult r = new HttpResult();
		r.setData(data);

		return r;
	}

	public static HttpResult ok() {
		return new HttpResult();
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMessage() {
		return  message;
	}

	public void setMessage(String  message) {
		this. message =  message;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

}
